package edu.nf.api.controller.rider;

import edu.nf.api.controller.BaseController;
import edu.nf.meituan.model.rider.Rider;
import edu.nf.meituan.service.rider.impl.RiderServiceImpl;
import edu.nf.util.JwtUtil;
import org.nf.web.annotation.RequestMapping;
import org.nf.web.annotation.RequestParam;
import org.nf.web.servlet.View;
import org.nf.web.servlet.view.JsonView;

import java.util.HashMap;


/**
 * @Date 2023-06-21
 * @Author qiu
 * 骑手登录
 */
public class LoginRiderController extends BaseController {
    /**
     * @param riderName  骑手姓名
     * @param riderPhone 骑手手机号
     * @return
     */
    @RequestMapping("/rider/login")
    public View riderLogin(@RequestParam("riderName") String riderName, @RequestParam("riderPhone") String riderPhone) {
        Rider rider = new RiderServiceImpl().loginRider(riderName, riderPhone);

        // 获取登录信息，存储到 token 中
        HashMap<String, Object> map = new HashMap<>();
        map.put("rider_phone", rider.getRiderPhone());

        // 创建 token
        String token = JwtUtil.createToken(map, 5 * 60 * 1000);

        return new JsonView(success(token));
    }

}
